package org.example.servlet;


import org.example.javabean.Collection;
import org.example.javabean.History;
import org.example.service.BookService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "insertCollectionServlet", urlPatterns = "/book/insertCollection")
public class insertCollectionServlet extends HttpServlet {

    private BookService bookService = new BookService();

    @Override
    protected void doGet(HttpServletRequest req,
                         HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req,
                          HttpServletResponse resp) throws ServletException, IOException {
        //1. 取参（req当前的页码, 每页的数量, 搜索）

        String book_id = req.getParameter("id");
        List<Collection> collections = new ArrayList<>();
        int insertresult = 0;
        insertresult  = bookService.insertCollectionBook(req.getSession(),book_id);

        //3. 将结果放入session
        req.getSession().setAttribute("insertresult ", insertresult);
        //将count直接作为ajax请求的结果返回
        resp.getWriter().print(insertresult);


    }
}
